package com.turman.builibrary.banner.indicator;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class BNumberIndicator extends FrameLayout implements IBIndicator<FrameLayout> {

    public BNumberIndicator(@NonNull Context context) {
        super(context);
    }

    public BNumberIndicator(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public BNumberIndicator(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void onInflate(int count) {
        removeAllViews();
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params.gravity = Gravity.CENTER | Gravity.BOTTOM;

        TextView textView = new TextView(getContext());
        textView.setTextColor(Color.WHITE);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP,18);

        textView.setText("1/"+count);
        addView(textView,params);
    }

    @Override
    public void onPointChange(int current, int count) {
        ((TextView)getChildAt(0)).setText((current+1)+"/"+count);
    }

    @Override
    public View getLayout() {
        return this;
    }
}
